// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ViewUI from 'view-design'
import 'view-design/dist/styles/iview.css'
import App from './App'
import { router } from './router/index'
import store from './store'
import i18n from '@/locale'
import { getRequest, postRequest, putRequest, postBodyRequest, getNoAuthRequest, postNoAuthRequest } from '@/libs/axios'
import { setStore, getStore, removeStore } from '@/libs/storage'
import { format } from "date-fns"
import util from '@/libs/util'
import hasPermission from '@/libs/hasPermission'
import hasRole from '@/libs/hasRole'
import iviewArea from '@/views/my-components/iview-area'
import VueLazyload from 'vue-lazyload'
import VueClipboard from 'vue-clipboard2'
import VueApexCharts from 'vue-apexcharts'
import './assets/iconfont/iconfont.css'
import '@babel/polyfill'
import filter from '@/libs/filter'
import VueAMap from 'vue-amap';
import Astrict from '@/libs/astrict'
// 
import * as Validate from '@/libs/validate'

//
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

import Cookies from 'js-cookie'
Vue.use(Cookies);

//
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'

Vue.use(Viewer)
Viewer.setDefaults({
    Options: {
        'inline': true, 'button': true, 'navbar': true, 'title': true, 'toolbar': true, 'tooltip': true, 'movable': true, 'zoomable': true, 'rotatable': true, 'scalable': true, 'transition': true, 'fullscreen': true, 'keyboard': true, 'url': 'data-source',
        maxZoomRatio: 70
    }
})

Vue.use(VueAMap);
VueAMap.initAMapApiLoader({  // 7158b5514c09fd9c429de6dc955e40c1
    key: '2925042861499671d3ef491fde5f274c',
    plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale',
        'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor', 'AMap.ControlBar',
        'AMap.setLabel',
        , 'AMap.MouseTool', 'AMap.GeometryUtil', 'AMap.DistrictSearch', 'AMap.Object3DLayer', 'AMap.DistrictLayer'],//需要的高德地图插件，需要什么插件添加什么插件（这里只是其中一部分）
    v: '1.4.4'
});

//高德的安全密钥   4b1d1aac7b3cfffc14aa0f6d9983bcb7
window._AMapSecurityConfig = {
    securityJsCode: '67791b00c8dfbfab0ac69fcb6db73d0d',
}
// 等待的图片
Vue.prototype.bus = new Vue;

// 全局导入过滤器
Vue.config.productionTip = false
Vue.use(VueLazyload, {
    error: require('./assets/img-error.png'),
    loading: require('./assets/loading2.gif')
})
Vue.use(ViewUI, {
    i18n: (key, value) => i18n.t(key, value)
});
Vue.use(VueClipboard);
Vue.use(hasPermission);
Vue.use(hasRole);
Vue.use(iviewArea);
Vue.use(VueApexCharts);
Vue.use(Astrict)

Vue.component('apexchart', VueApexCharts);
// 挂载全局使用的方法
Vue.prototype.Validate = Validate;
Vue.prototype.getRequest = getRequest;
Vue.prototype.postRequest = postRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.postBodyRequest = postBodyRequest;
Vue.prototype.getNoAuthRequest = getNoAuthRequest;
Vue.prototype.postNoAuthRequest = postNoAuthRequest;
Vue.prototype.setStore = setStore;
Vue.prototype.getStore = getStore;
Vue.prototype.removeStore = removeStore;
Vue.prototype.format = format;
// Vue.prototype.$baseUrl = 'http://113.133.177.216:8089/platformrules/'
Vue.prototype.$baseUrl = 'http://weiyunyun.cn:8089/platformrules/'
// Vue.prototype.$baseUrl = 'http://192.168.0.103:8089/platformrules/'
Vue.prototype.$rowEditFormNumToStr = (form, row) => {
    Object.keys(form).forEach(key => {
        form[key] = typeof row[key] === 'number' && isFinite(row[key]) ? `${row[key]}` : row[key]
    })
    return form
}

Object.keys(filter).forEach(key => Vue.filter(key, filter[key]))
/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    i18n,
    render: h => h(App),
    data: {
        currentPageName: ''
    },
    mounted() {
        // 初始化菜单
        util.initRouter(this);
        // 初始化全局数据字典
        this.currentPageName = this.$route.name;
        // 显示打开的页面的列表
        this.$store.commit('setOpenedList');
        this.$store.commit('initCachepage');
        setStore
        let params = {
            userId: JSON.parse(Cookies.get("userInfo")).id,
            status: 0,
            pageNumber: 1, // 当前页数
            pageSize: 10, // 页面大小
            sort: "createTime", // 默认排序字段
            order: "desc", // 默认排序方式
        }
    }
})
